# -*- coding:utf-8 -*-
"""
全局配置文件，提供常量信息
"""
import os
import logging
import sys

module_logger = logging.getLogger("logger")

class Config():
    """
    @ClassName：Config
    @Description： 本项目只创建一个 Config 实例
    负责常用属性配置，包括窗体颜色，文件路径，字体等
    """
    _instance = None  # 类变量，用于存储唯一实例
    

    # 主函数启动的绝对路径
    CURRENT_PATH = os.path.abspath('.')

    try:
        CURRENT_PATH = sys._MEIPASS  # pyinstaller打包后的路径
    except AttributeError:
        CURRENT_PATH = os.path.abspath(".")  # 当前工作目录的路径

    ICON_PATH = os.path.join(CURRENT_PATH, "views\\rcc\\icon.ico")
    SEARCH_ICON = os.path.join(CURRENT_PATH, "views\\assets\\search.png")
    
    EARTH_PATH=os.path.join(CURRENT_PATH, "views\\assets\\earth.gif")
    
    LABEL_HEADBG = os.path.join(CURRENT_PATH, "views\\assets\\header_bg.png")
    LABEL_TITLEBG = os.path.join(CURRENT_PATH, "views\\assets\\header_title.png")
    LOGIN_BG = os.path.join(CURRENT_PATH, "views\\assets\\background.png")
    
    WELCOME_BG = os.path.join(CURRENT_PATH, "views\\assets\\bg.png")
    #excel上传保存文件夹
    EXCEL_DIR = "excel"
    # 封面保存文件夹
    IMG_SAVE_DIR = "upload_imgs"
    # 统计图保存文件夹
    STATS_IMG_SAVE_DIR = "stats_imgs"
    #地图目录
    MAP_SAVE_DIR = "map"
    # excel保存路径
    EXCEL_SAVE_PATH = os.path.join(CURRENT_PATH, EXCEL_DIR)
    # 图片保存路径
    IMG_SAVE_PATH = os.path.join(CURRENT_PATH, IMG_SAVE_DIR)
    # 统计图片路径
    STATS_IMG_SAVE_PATH = os.path.join(CURRENT_PATH, STATS_IMG_SAVE_DIR)
    
    
    # 数据持久化文件路径（json）
    #DATA_JSON_PATH = os.path.join(CURRENT_PATH, "repositories\\json\\data.json")
    # 字体文件路径
    FONT_PATH = os.path.join(CURRENT_PATH, "views\\fonts\\Alibaba-PuHuiTi-Regular.ttf")

    @staticmethod
    def create_directory(directory):
        
        if not os.path.exists(directory):
            os.makedirs(directory)
            module_logger.info(f"创建文件夹{directory}")
        else:
            module_logger.info(f"文件夹{directory}已存在")

    def __new__(cls):
        # __new__ 方法确保只创建一个实例
        if not cls._instance:
            cls._instance = super().__new__(cls)
            cls.create_directory(cls.EXCEL_SAVE_PATH)
            cls.create_directory(cls.IMG_SAVE_PATH)
            cls.create_directory(cls.STATS_IMG_SAVE_PATH)
            cls.create_directory(cls.MAP_SAVE_DIR)
        return cls._instance


